package ink.lovejinhu.leetcode;

/**
 * @Author: jin
 * @Date: 2021/9/13 18:02
 * @Version: V1.0
 * @Slogan: Great people are not born great, but show their greatness in the process of growing up
 **/
public class Solution_0925 {
    /**
     * 其实就是看name是不是typed的子序列
     *
     * @param name
     * @param typed
     * @return
     */
    public boolean isLongPressedName(String name, String typed) {
        int j = 0;
        int match = Integer.MAX_VALUE;
        if (name.charAt(0) == typed.charAt(0)) {
            match = 0;
        } else {
            return false;
        }

        for (int i = 0; i < typed.length(); i++) {
            if (j >= name.length()) {
                /**
                 * 一定要保证后续的是相同字符
                 */
                for (int k = i; k < typed.length(); k++) {
                    if (typed.charAt(k) == typed.charAt(k - 1)) {
                        continue;
                    } else {
                        return false;
                    }
                }
                return true;
            }
            if (typed.charAt(i) == name.charAt(j)) {
                j++;
                match = i;  //记录此次匹配的位置
            } else {
                if (typed.charAt(i) == typed.charAt(match)) {
                    continue;
                } else {
                    return false;
                }
            }
        }
        return j >= name.length();
    }
}
